<?php
// +----------------------------------------------------------------------
// | Bwsaas
// +----------------------------------------------------------------------
// | Copyright (c) 2015~2020 http://www.buwangyun.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Gitee ( https://gitee.com/buwangyun/bwsaas )
// +----------------------------------------------------------------------
// | Author: buwangyun <hnlg666@163.com>
// +----------------------------------------------------------------------
// | Date: 2020-9-28 10:55:00
// +----------------------------------------------------------------------

namespace buwang\middleware;

class InstallCheck
{
    public function handle($request, \Closure $next)
    {
        $path = $request->baseUrl() ?? '';

        $lockFile = root_path() . 'install.lock';

        if (!file_exists($lockFile) && !str_starts_with($path, '/install')) {
            return response('', 302, ['Location' => '/install.php']);
        }

        return $next($request);
    }
}
